package ipsite.controller;

  import java.io.BufferedReader;
import java.io.FileReader;


import javax.jms.JMSException;
   import org.apache.activemq.ActiveMQConnectionFactory;

  import javax.jms.Connection;
  import javax.jms.DeliveryMode;
  import javax.jms.Destination;

  import javax.jms.MessageProducer;
  import javax.jms.Session;
  import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnection;
  
  /**
   *
   * @author gisbert.amm
   */
  public class Queue {
  
      private static ActiveMQConnectionFactory connectionFactory;
      private static Connection connection;
      private static Session session;
      private static Destination destination;
      private static boolean transacted = false;
  
//      public static void main(String[] args) throws Exception {
//         
//
//    	  
////    	  for(int i=0;i<10;i++)
////    	  {
//	          setUp();
//	          
//	          
//	          BufferedReader reader = new BufferedReader(new FileReader("g:/abc.txt"));
//	          
//	          while(1==1)
//	          {
//	        	  String str = reader.readLine();
//	        	  if(str==null) break;
//	        	  createProducerAndSendAMessage(str);
//	        	  
//	          }
////    	  }
//         
//  
//          //TODO: Find out how to get rid of the exceptions thrown when stopping the broker
//         
//      }
  
      private static void setUp() throws JMSException {
          connectionFactory = new ActiveMQConnectionFactory(
                  ActiveMQConnection.DEFAULT_USER,
                  ActiveMQConnection.DEFAULT_PASSWORD,
                  "tcp://y1s.org:61616");
          connection = connectionFactory.createConnection();
          connection.start();
          session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
          destination = session.createQueue("domain");
      }
  
      private static void createProducerAndSendAMessage(String str) throws JMSException {
    	  
          MessageProducer producer = session.createProducer(destination);
          producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
          TextMessage message = session.createTextMessage(str);
          System.out.println("Sending message: " + message.getText());
          producer.send(message);
      }
  
     
  
     
  }